# Maintainer: Maxime Gauduin <alucryd@archlinux.org>
# Contributor: Chocobo1 <chocobo1@archlinux.net>
# Contributor: Jean Lucas <jean@4ray.co>

pkgname=sccache
pkgver=0.7.3
pkgrel=1
pkgdesc='Shared compilation cache'
arch=(loong64 x86_64)
url=https://github.com/mozilla/sccache
license=(Apache)
depends=(
  gcc-libs
  glibc
  openssl
  zlib
  zstd
)
makedepends=(
  git
  rust
)
optdepends=(
  'memcached: Memcached support'
  'redis: Redis support'
)
_tag=7cca55a4ac24cab10cb63cf4e41542c96ccb7c9d
source=(git+https://github.com/mozilla/sccache.git#tag=${_tag})
b2sums=(SKIP)

pkgver() {
  cd sccache
  git describe --tags | sed 's/^v//'
}

prepare() {
#  find -name Cargo.lock -exec rm -f {} \;
#  mkdir -p .cargo
#  cat > .cargo/config.toml <<EOF
#[source.crates-io]
#registry = "https://gitee.com/yetist/crates.io-index"
#EOF
  cargo fetch \
    --manifest-path sccache/Cargo.toml
}

build() {
  export CFLAGS+=' -ffat-lto-objects'
  export LDFLAGS+=' -lzstd'
#  find -name Cargo.lock -exec rm -f {} \;
#  mkdir -p .cargo
#  cat > .cargo/config.toml <<EOF
#[source.crates-io]
#registry = "https://gitee.com/yetist/crates.io-index"
#EOF
  cargo build \
    --release \
    --manifest-path sccache/Cargo.toml \
    --features all,dist-server,native-zlib
}

#check() {
#  cargo test \
#    --release \
#    --frozen \
#    --manifest-path sccache/Cargo.toml \
#    --features all,dist-server,native-zlib
#}

package() {
  export CFLAGS+=' -ffat-lto-objects'
  export LDFLAGS+=' -lzstd'
  cargo install \
    --frozen \
    --offline \
    --no-track \
    --path sccache \
    --root "${pkgdir}"/usr \
    --features all,dist-server,native-zlib
}

# vim: ts=2 sw=2 et:
